﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using EnvDTE80;
using Rhino.Mocks;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class ItemCommandContextFixture
	{
		[Test]
		public void HiddenCommandOnMultiselctionWithSingleItemCompatibility()
		{
			var selectedItemsAdapter = MockRepository.GenerateStub<SelectedItemsAdapter>((DTE2)null);
			selectedItemsAdapter.Stub(x => x.IsMultiSelect()).Return(true);

			var cmdContext = new ItemCommandContext(selectedItemsAdapter, null, new SingleItemCompatibility());
			var status = cmdContext.GetCommandStatus();

			Assert.AreEqual(CommandStatus.Invisible, status);
		}

		[Test]
		public void ShowCommandAlwaysOnMultiselctionWithMultiItemCompatibility()
		{
			var selectedItemsAdapter = MockRepository.GenerateStub<SelectedItemsAdapter>((DTE2)null);
			selectedItemsAdapter.Stub(x => x.GetSelectedPaths()).Return(new List<string> { @"c:\svn\pippo.txt" });

			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Stub(x => x.CanExecuteCommandsOnPath(@"c:\svn\pippo.txt")).Return(true);

			var cmdContext = new ItemCommandContext(selectedItemsAdapter, workingContext, new MultiItemCompatibility());
			var status = cmdContext.GetCommandStatus();

			Assert.AreEqual(CommandStatus.Enabled, status);
		}

		[Test]
		public void OnMultiselctionDisabledWhenWorkingContextDenyExecutionOnAnItem()
		{
			var selectedItemsAdapter = MockRepository.GenerateStub<SelectedItemsAdapter>((DTE2)null);
			selectedItemsAdapter.Stub(x => x.GetSelectedPaths()).Return(new List<string> { @"c:\svn\pippo.txt", @"c:\svn\pippo2.txt" });

			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Stub(x => x.CanExecuteCommandsOnPath(@"c:\svn\pippo.txt")).Return(true);
			workingContext.Stub(x => x.CanExecuteCommandsOnPath(@"c:\svn\pippo2.txt")).Return(false);

			var cmdContext = new ItemCommandContext(selectedItemsAdapter, workingContext, new MultiItemCompatibility());
			var status = cmdContext.GetCommandStatus();

			Assert.AreEqual(CommandStatus.Disabled, status);
		}

		[Test]
		public void OnMultiselctionGetAllExecutionPaths()
		{
			var selectedItemsAdapter = MockRepository.GenerateStub<SelectedItemsAdapter>((DTE2)null);
			selectedItemsAdapter.Stub(x => x.GetSelectedPaths()).Return(new List<string> { @"c:\svn\pippo.txt", @"c:\svn\pippo2.txt" });

			var cmdContext = new ItemCommandContext(selectedItemsAdapter, null, new MultiItemCompatibility());
			var path = cmdContext.GetWorkingPath();

			Assert.AreEqual(path, @"c:\svn\pippo.txt*c:\svn\pippo2.txt");
		}
	}
}
